package com.drcoffee.drcoffeemall.service.impl;

import com.drcoffee.drcoffeemall.entry.Result;
import com.drcoffee.drcoffeemall.service.FileService;
import com.drcoffee.drcoffeemall.util.OSSUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Service
public class FileServiceImpl implements FileService {
    @Autowired
    OSSUtil ossUtil;

    @Override
    public Result uploadImage(MultipartFile file, String fileName, Integer type) {
        try {
            String file_path = "";
            if (type == 1) {
                //头像
                file_path = "PartsMallFile/avatar/";
            } else if (type == 2) {
                // 反馈图
                file_path = "PartsMallFile/feedback/";
            } else if (type == 3) {
                // 转账凭证
                file_path = "PartsMallFile/payVoucher/";
            }
            return ossUtil.upload(file, file_path, fileName);
        } catch (Exception e) {
            log.error("===================== uploadImage()异常： =====================", e);
            return new Result(-1, "ERROR", e.getMessage(), null);
        }
    }

    @Override
    public Result uploadFileList(MultipartFile[] files) {
        String file_path = "PartsMallFile/AfterSale/";
        return ossUtil.uploadFileList(files, file_path);
    }
}
